package cn.iocoder.yudao.boot.jpa.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.time.LocalDateTime;

@JsonIgnoreProperties(value = {"hibernateLazyInitializer"})
@Data
@MappedSuperclass
public abstract class BaseEntity {
    /**
     * id
     */
    @Id
    private Long id;

    /**
     * 创建人
     */
    private Long createBy;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新人
     */
    private Long updateBy;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 删除标记 --系统只做逻辑删除
     */
    @Column(length = 1, insertable = true)
    private Boolean deleted = Boolean.FALSE;

    @PrePersist
    public void setCreateTime() {
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
    }

    @PreUpdate
    public void setUpdateTime() {
        this.updateTime = LocalDateTime.now();
    }
}
